<?php

declare(strict_types=1);

namespace app\core\DB;

use Swoole\Coroutine;
class DBPool{
    private static $pool = [];
    protected static $name='Resource.database';
    static function get()
    {
        $cid = Coroutine::getuid();
        if ($cid < 0) {
            return null;
        }
        if(isset(self::$pool[$cid][self::$name])){
            return self::$pool[$cid][self::$name];
        }

        return null;
    }

    static function put($item)
    {
        $cid = Coroutine::getuid();
        if ($cid > 0) {
            self::$pool[$cid][self::$name] = $item;
        }
    }

    static function delete()
    {
        $cid = Coroutine::getuid();
        if ($cid > 0) {
          
            
            Db::getInstance()->release();
           
         
            unset(self::$pool[$cid][self::$name]);
        }
    }
    

    
}